import { defineStore } from 'pinia'

interface UserState {
    counter: number;
    save: string;
    dev: string;
  }

export const useMainStore = defineStore({
  // name of the store
  // it is used in devtools and allows restoring state
  id: 'main',
  
  // a function that returns a fresh state
  state: () : UserState => ({
    counter: 1,
    save: 'Vite@2.0 + Vue@3.0 + Vuex@4.0 + vue-router@4.0 + Typescript4.0 + Element puls ',
    dev: 'vite-plugin-style-import + pinia'
  }),
  // optional getters
  getters: {
    doubleCount(): number {
      return this.counter * 2
    },
    // use getters in other getters
    doubleCountPlusOne():number {
      return this.doubleCount * 2 + 1
    },
  },
  // optional actions
  actions: {
    reset() {
      // `this` is the store instance
      this.counter = 0
    },
  },
})